package com.gr.experimental.model.impl;

import com.gr.experimental.model.RVClass;
import com.gr.experimental.model.RVState;
import com.gr.experimental.model.UID;


/**
 * Class of objects representing a single random variable state.
 * It binds the random variable with one of the states that it make take
 * without the Absurd state.
 */
class RVStateImpl implements RVState {
	RVClass rvClass;
	UID uid;
	public RVStateImpl(RVClass rvClass, UID uid) {
		this.rvClass = rvClass;
		this.uid = uid;
	}
	
	/**
	 * {@inheritDoc}
	 * @see com.gr.experimental.model.RVState#getRVClass()
	 */
	public RVClass getRVClass() {
		return this.rvClass;
	}


	/**
	 * {@inheritDoc}
	 * @see com.gr.experimental.model.RVState#getUid()
	 */
	public UID getUid() {
		return this.uid;
	}




	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((uid == null) ? 0 : uid.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final RVStateImpl other = (RVStateImpl) obj;
		if (uid == null) {
			if (other.uid != null)
				return false;
		} else if (!uid.equals(other.uid))
			return false;
		return true;
	}

	@Override
	public String getName() {
		return rvClass.getName() +"." + uid.getValue();
	}
	
}